package cn.stylefeng.guns.modular.gridsystem.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.model.param.GatewayTaskParam;
import cn.stylefeng.guns.modular.gridsystem.service.GatewayTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 网关任务下发表 控制器
 *
 * @author: zxw
 * @date: 2022/10/31 14:34
 */
@RestController
@Slf4j
@RequiredArgsConstructor
public class GatewayTaskController {

    private final GatewayTaskService gatewayTaskService;

    /**
     * 分页查询网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @GetMapping("/gatewayTask/page")
    @BusinessLog(title = "网关任务下发表_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(GatewayTaskParam gatewayTaskParam) {
        return new SuccessResponseData(gatewayTaskService.page(gatewayTaskParam));
    }

    /**
     * 分页查询网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @GetMapping("/gatewayTask/pageTask")
    @BusinessLog(title = "网关任务下发表_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData pageTaskList(GatewayTaskParam gatewayTaskParam) {
        return new SuccessResponseData(gatewayTaskService.pageTaskList(gatewayTaskParam));
    }

    /**
     * 获取全部网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @GetMapping("/gatewayTask/list")
    @BusinessLog(title = "网关任务下发表_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list() {
        return new SuccessResponseData(gatewayTaskService.list());
    }

    /**
     * 查看详情网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @GetMapping("/gatewayTask/detail")
    @BusinessLog(title = "网关任务下发表_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(GatewayTaskParam.detail.class) GatewayTaskParam gatewayTaskParam) {
        return new SuccessResponseData(gatewayTaskService.detail(gatewayTaskParam));
    }

    /**
     * 添加网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @PostMapping("/gatewayTask/add")
    @BusinessLog(title = "网关任务下发表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(GatewayTaskParam.add.class) GatewayTaskParam gatewayTaskParam) {
        gatewayTaskService.add(gatewayTaskParam);
        return new SuccessResponseData();
    }

    /**
     * 下发任务
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @PostMapping("/gatewayTask/issued")
    @BusinessLog(title = "网关任务下发表_下发", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData issued(@RequestBody @Validated(GatewayTaskParam.issued.class) GatewayTaskParam gatewayTaskParam) {
        gatewayTaskService.issued(gatewayTaskParam);
        return new SuccessResponseData();
    }

    /**
     * 撤回任务
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @PostMapping("/gatewayTask/rollback")
    @BusinessLog(title = "网关任务下发表_撤回", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData rollback(@RequestBody @Validated(GatewayTaskParam.rollback.class) GatewayTaskParam gatewayTaskParam) {
        gatewayTaskService.rollback(gatewayTaskParam);
        return new SuccessResponseData();
    }

    /**
     * 删除网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @PostMapping("/gatewayTask/delete")
    @BusinessLog(title = "网关任务下发表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(GatewayTaskParam.delete.class) GatewayTaskParam gatewayTaskParam) {
        gatewayTaskService.delete(gatewayTaskParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑网关任务下发表
     *
     * @author zxw
     * @date 2022/10/31 14:34
     */
    @PostMapping("/gatewayTask/edit")
    @BusinessLog(title = "网关任务下发表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(GatewayTaskParam.edit.class) GatewayTaskParam gatewayTaskParam) {
        gatewayTaskService.edit(gatewayTaskParam);
        return new SuccessResponseData();
    }

}
